// pages/my/myInfo_order_info/myInfo_order_info.js
const API = require('../../../API/api.js');
const app = getApp();
Page({
    pay() {
        var openId = wx.getStorageSync('token').openid;
        //下单调用微信支付
        API.order({
            orderId: this.data.orderId,
            openId: openId
        }).then((res) => {
            wx.requestPayment({
                'timeStamp': res.data.timeStamp,
                'nonceStr': res.data.nonceStr,
                'package': res.data.package,
                'signType': 'MD5',
                'paySign': res.data.paySign,
                'success': function (res) {
                    console.log(res)
                    wx.navigateTo({
                        url: '../../payResult/payResult?orderId=' + res.data,
                    })
                },
                'fail': function (res) {
                    console.log(res)
                    wx.navigateTo({
                        url: '../../payResult/payResult?orderId=' + res.data,
                    })
                }
            })
        })
    },
    getOrderDetail: function () {
        API.getOrderDetail({
            userId: wx.getStorageSync('userId'),
            orderId: this.data.orderId
        }).then((res) => {
            console.log(res);
            this.setData({
                oderDetail: res.data

            })
        })
    },
    confirmation() {
        API.orderConfirmation({
            orderId: this.data.orderId,
            userId: wx.getStorageSync('userId')
        }).then((res) => {
            console.log(res)
        })
    },
    /**
     * 页面的初始数据
     */
    data: {
        Height: 0,
        orderId: '',
        oderDetail: {},
        imgUrl: app.globalData.imgUrl
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let orderId = options.orderId;
        this.setData({
            orderId: orderId
        });
        this.getOrderDetail()
        let that = this;
        wx.getSystemInfo({
            success: function (res) {
                that.setData({
                    Height: res.windowHeight * 2
                })
            },
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})
